const baseUrl = "xxx";

let requestCount = 0; //解决loading闪烁

export default (options) => {
  requestCount++;
  uni.showLoading({
    title: "加载中...",
  });

  return new Promise((resolve, reject) => {
    uni.request({
      ...options,
      url: baseUrl + options.url,
      success: (res) => {
        resolve(res.data);
      },
      fail: (err) => {
        reject(err);
      },
      complete: () => {
        requestCount--;
        if (requestCount === 0) {
          uni.hideLoading();
        }
      },
    });
  });
};
